#!/bin/Rscript

on_100 <- read.table("on/profits.dat")$V1
op_100 <- read.table("rf/profits.dat")$V1
ut_100 <- read.table("ut/profits.dat")$V1
iosup_100 <- read.table("iosup/profits.dat")$V1
super_100 <- read.table("super/profits.dat")$V1

# Testes de hipoteses
print("100 us 1_5_10% hi == on")
wilcox.test(ut_100, on_100, paired=TRUE, var.equal=FALSE)
print("hi > on")
wilcox.test(ut_100, on_100, paired=TRUE, var.equal=FALSE, alternative="less")

print("op == on")
wilcox.test(op_100, on_100, paired=TRUE, var.equal=FALSE)
print("op > on")
wilcox.test(op_100, on_100, paired=TRUE, var.equal=FALSE, alternative="less")

print("iosup == on")
wilcox.test(iosup_100, on_100, paired=TRUE, var.equal=FALSE)
print("iosup > on")
wilcox.test(iosup_100, on_100, paired=TRUE, var.equal=FALSE, alternative="less")

print("super == on")
wilcox.test(super_100, on_100, paired=TRUE, var.equal=FALSE)
print("super > on")
wilcox.test(super_100, on_100, paired=TRUE, var.equal=FALSE, alternative="less")

print("hi == op")
wilcox.test(ut_100, op_100, paired=TRUE, var.equal=FALSE)
print("hi > op")
wilcox.test(ut_100, op_100, paired=TRUE, var.equal=FALSE, alternative="less")
print("hi < op")
wilcox.test(ut_100, op_100, paired=TRUE, var.equal=FALSE, alternative="greater")

print("hi == iosup")
wilcox.test(ut_100, iosup_100, paired=TRUE, var.equal=FALSE)
print("hi > iosup")
wilcox.test(ut_100, iosup_100, paired=TRUE, var.equal=FALSE, alternative="less")
print("hi < iosup")
wilcox.test(ut_100, iosup_100, paired=TRUE, var.equal=FALSE, alternative="greater")

print("op == iosup")
wilcox.test(op_100, iosup_100, paired=TRUE, var.equal=FALSE)
print("op > iosup")
wilcox.test(op_100, iosup_100, paired=TRUE, var.equal=FALSE, alternative="less")
print("op < iosup")
wilcox.test(op_100, iosup_100, paired=TRUE, var.equal=FALSE, alternative="greater")

print("op == super")
wilcox.test(op_100, super_100, paired=TRUE, var.equal=FALSE)
print("op > super")
wilcox.test(op_100, super_100, paired=TRUE, var.equal=FALSE, alternative="less")
print("op < super")
wilcox.test(op_100, super_100, paired=TRUE, var.equal=FALSE, alternative="greater")

print("ut == super")
wilcox.test(ut_100, super_100, paired=TRUE, var.equal=FALSE)
print("ut > super")
wilcox.test(ut_100, super_100, paired=TRUE, var.equal=FALSE, alternative="less")
print("ut < super")
wilcox.test(ut_100, super_100, paired=TRUE, var.equal=FALSE, alternative="greater")

print("iosup == super")
wilcox.test(iosup_100, super_100, paired=TRUE, var.equal=FALSE)
print("iosup > super")
wilcox.test(iosup_100, super_100, paired=TRUE, var.equal=FALSE, alternative="less")
print("iosup < super")
wilcox.test(iosup_100, super_100, paired=TRUE, var.equal=FALSE, alternative="greater")


# >>>>>> Resumos dos profits
print(">>>>>>>> LUCROS 100 1_5_10")
paste("OP", mean(op_100), "[", 1.96*sd(op_100)/sqrt(length(op_100))+mean(op_100), ":", mean(op_100) - 1.96*sd(op_100)/sqrt(length(op_100)), "]")
paste("UT", mean(ut_100), "[", 1.96*sd(ut_100)/sqrt(length(ut_100))+mean(ut_100), ":", mean(ut_100) - 1.96*sd(ut_100)/sqrt(length(ut_100)), "]")
paste("Iosup", mean(iosup_100), "[", 1.96*sd(iosup_100)/sqrt(length(iosup_100))+mean(iosup_100), ":", mean(iosup_100) - 1.96*sd(iosup_100)/sqrt(length(iosup_100)), "]")
paste("Super", mean(super_100), "[", 1.96*sd(super_100)/sqrt(length(super_100))+mean(super_100), ":", mean(super_100) - 1.96*sd(super_100)/sqrt(length(super_100)), "]")
paste("ON", mean(on_100), "[", 1.96*sd(on_100)/sqrt(length(on_100))+mean(on_100), ":", mean(on_100) - 1.96*sd(on_100)/sqrt(length(on_100)), "]")

paste("Média geral lucro UT: ", mean(c(ut_100)))
paste("Média geral lucro RF: ", mean(c(op_100)))
paste("Média geral lucro Iosup: ", mean(c(iosup_100)))
paste("Média geral lucro Super: ", mean(c(super_100)))
paste("Média geral lucro ON: ", mean(c(on_100)))


#>>>>>>>>> Ganhos para risco de 1_5_10%

gop_100_1 <- (op_100 - on_100) / abs(on_100)
gut_100_1 <- (ut_100 - on_100) / abs(on_100)
giosup_100_1 <- (iosup_100 - on_100) / abs(on_100)
gsuper_100_1 <- (super_100 - on_100) / abs(on_100)

print(">>>> GANHOS 100 1_5_10% 20%")
paste("Ganhos hi --> on", mean(ut_100 - on_100), " [", 1.96*sd(ut_100 - on_100)/sqrt(length(ut_100 - on_100))+mean(ut_100 - on_100), ":",  mean(ut_100 - on_100) - 1.96*sd(ut_100 - on_100)/sqrt(length(ut_100 - on_100)), "]", " ", mean(gut_100_1), " [", 1.96*sd(gut_100_1)/sqrt(length(gut_100_1))+mean(gut_100_1), ":",  mean(gut_100_1) - 1.96*sd(gut_100_1)/sqrt(length(gut_100_1)), "]" )
print(paste(gut_100_1))

paste("Ganhos op --> on", mean(op_100 - on_100), " [", 1.96*sd(op_100 - on_100)/sqrt(length(op_100 - on_100))+mean(op_100 - on_100), ":",  mean(op_100 - on_100) - 1.96*sd(op_100 - on_100)/sqrt(length(op_100 - on_100)), "]", " ", mean(gop_100_1), " [", 1.96*sd(gop_100_1)/sqrt(length(gop_100_1))+mean(gop_100_1), ":",  mean(gop_100_1) - 1.96*sd(gop_100_1)/sqrt(length(gop_100_1)), "]" )
print(paste(gop_100_1))

paste("Ganhos iosup --> on", mean(iosup_100 - on_100), " [", 1.96*sd(iosup_100 - on_100)/sqrt(length(iosup_100 - on_100))+mean(iosup_100 - on_100), ":",  mean(iosup_100 - on_100) - 1.96*sd(iosup_100 - on_100)/sqrt(length(iosup_100 - on_100)), "]", " ", mean(giosup_100_1), " [", 1.96*sd(giosup_100_1)/sqrt(length(giosup_100_1))+mean(giosup_100_1), ":",  mean(giosup_100_1) - 1.96*sd(giosup_100_1)/sqrt(length(giosup_100_1)), "]" )
print(paste(giosup_100_1))

paste("Ganhos super --> on", mean(super_100 - on_100), " [", 1.96*sd(super_100 - on_100)/sqrt(length(super_100 - on_100))+mean(super_100 - on_100), ":",  mean(super_100 - on_100) - 1.96*sd(super_100 - on_100)/sqrt(length(super_100 - on_100)), "]", " ", mean(gsuper_100_1), " [", 1.96*sd(gsuper_100_1)/sqrt(length(gsuper_100_1))+mean(gsuper_100_1), ":",  mean(gsuper_100_1) - 1.96*sd(gsuper_100_1)/sqrt(length(gsuper_100_1)), "]" )
print(paste(gsuper_100_1))

paste("Média geral ganho % UT: ", mean(c(gut_100_1)))
paste("Média geral ganho % RF: ", mean(c(gop_100_1)))
paste("Média geral ganho % Iosup: ", mean(c(giosup_100_1)))
paste("Média geral ganho % Super: ", mean(c(gsuper_100_1)))

paste("Média geral diferenca $ UT: ", mean(c(ut_100 - on_100)))
paste("Média geral diferenca $ RF: ", mean(c(op_100 - on_100)))
paste("Média geral diferenca $ Iosup: ", mean(c(iosup_100 - on_100)))
paste("Média geral diferenca $ Super: ", mean(c(super_100 - on_100)))
